<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>OptionsPricing: testPdeSolvers.py Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">OptionsPricing
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="dir_c561bed9bc117923e059a4705c79b8c4.html">regression</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">testPdeSolvers.py</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">#!/usr/bin/python</span>
<a name="l00002"></a>00002 <span class="comment"># -*- coding: utf-8 -*-</span>
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 <span class="comment"># Copyright (c) 2011</span>
<a name="l00005"></a>00005 <span class="comment">#</span>
<a name="l00006"></a>00006 <span class="comment"># Permission is hereby granted, free of charge, to any person obtaining a</span>
<a name="l00007"></a>00007 <span class="comment"># copy of this software and associated documentation files (the &quot;Software&quot;),</span>
<a name="l00008"></a>00008 <span class="comment"># to deal in the Software without restriction, including without limitation</span>
<a name="l00009"></a>00009 
<a name="l00010"></a>00010 <span class="comment"># the rights to use, copy, modify, merge, publish, distribute, sublicense,</span>
<a name="l00011"></a>00011 <span class="comment"># and/or sell copies of the Software, and to permit persons to whom the</span>
<a name="l00012"></a>00012 <span class="comment"># Software is furnished to do so, subject to the following conditions:</span>
<a name="l00013"></a>00013 <span class="comment">#</span>
<a name="l00014"></a>00014 <span class="comment"># The above copyright notice and this permission notice shall be included in</span>
<a name="l00015"></a>00015 <span class="comment"># all copies or substantial portions of the Software.</span>
<a name="l00016"></a>00016 <span class="comment">#</span>
<a name="l00017"></a>00017 <span class="comment"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<a name="l00018"></a>00018 <span class="comment"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<a name="l00019"></a>00019 <span class="comment"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<a name="l00020"></a>00020 <span class="comment"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<a name="l00021"></a>00021 <span class="comment"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<a name="l00022"></a>00022 <span class="comment"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE</span>
<a name="l00023"></a>00023 <span class="comment"># SOFTWARE.</span>
<a name="l00024"></a>00024 <span class="comment">#</span>
<a name="l00025"></a>00025 <span class="comment"># Author: Jesus Carrero &lt;j.o.carrero@gmail.com&gt;</span>
<a name="l00026"></a>00026 <span class="comment"># Mountain View, CA</span>
<a name="l00027"></a>00027 <span class="comment">#</span>
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 <span class="keyword">from</span> numpy <span class="keyword">import</span> log2, exp, cos, sin, ones, c_
<a name="l00030"></a>00030 <span class="keyword">from</span> numpy <span class="keyword">import</span> linalg, asarray, empty, meshgrid
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 <span class="keyword">from</span> scipy <span class="keyword">import</span> linspace
<a name="l00033"></a>00033 
<a name="l00034"></a>00034 <span class="keyword">from</span> utils.Quadrature <span class="keyword">import</span> LegendreGaussQuadrature
<a name="l00035"></a>00035 <span class="keyword">from</span> utils.FemBases <span class="keyword">import</span> LagrangeP1, LagrangeP2
<a name="l00036"></a>00036 <span class="keyword">from</span> utils.ProjOperators <span class="keyword">import</span> ProjOnShapeFunctions
<a name="l00037"></a>00037 <span class="keyword">from</span> utils.FemToReal <span class="keyword">import</span> FemToReal
<a name="l00038"></a>00038 <span class="keyword">from</span> utils.Grid <span class="keyword">import</span> Grid1D
<a name="l00039"></a>00039 <span class="keyword">from</span> utils.Spline <span class="keyword">import</span> Spline
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 <span class="keyword">from</span> models.CDRSolver <span class="keyword">import</span> CDRSolver
<a name="l00042"></a>00042 <span class="keyword">from</span> models.SecondOrderStatic1D <span class="keyword">import</span> SecondOrderStatic1D
<a name="l00043"></a>00043 <span class="keyword">from</span> models.Poisson2DFiniteDifference <span class="keyword">import</span> Poisson2DFiniteDifference
<a name="l00044"></a>00044 <span class="keyword">from</span> models.AssembleStiffnesMassMatrices <span class="keyword">import</span> AssembleStiffnesMassMatrices
<a name="l00045"></a>00045 
<a name="l00046"></a>00046 <span class="keyword">from</span> solvers.DirichletTimeStepper <span class="keyword">import</span> DirichletTimeStepper
<a name="l00047"></a>00047 
<a name="l00048"></a>00048 <span class="keyword">from</span> input_output.DerivativePlots <span class="keyword">import</span> DerivativePlots
<a name="l00049"></a>00049 
<a name="l00050"></a>00050 <span class="keyword">from</span> scipy.sparse.construct <span class="keyword">import</span> spdiags
<a name="l00051"></a>00051 
<a name="l00052"></a>00052 <span class="keyword">import</span> logging
<a name="l00053"></a>00053 <span class="keyword">from</span> utils.MainLog <span class="keyword">import</span> runGlobalLogger
<a name="l00054"></a>00054 
<a name="l00055"></a>00055 <span class="keyword">import</span> unittest
<a name="l00056"></a>00056 
<a name="l00057"></a>00057 (d, c, r) = (-1., 2.0, 0.50)
<a name="l00058"></a>00058 
<a name="l00059"></a>00059 
<a name="l00060"></a><a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html">00060</a> <span class="keyword">class </span><a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html">PdeTestSuite</a>(unittest.TestCase):
<a name="l00061"></a>00061     <span class="stringliteral">&quot;&quot;&quot; test elliptic and parabolic solver. &quot;&quot;&quot;</span>
<a name="l00062"></a>00062 
<a name="l00063"></a>00063     @classmethod
<a name="l00064"></a><a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#a9a0a656f2076feb5d3f784b6d404bf87">00064</a>     <span class="keyword">def </span><a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#a9a0a656f2076feb5d3f784b6d404bf87">cinf_solution</a>(cls, points, time=0):  <span class="comment"># Test 1</span>
<a name="l00065"></a>00065         <span class="stringliteral">&quot;&quot;&quot; exact solution. &quot;&quot;&quot;</span>
<a name="l00066"></a>00066         <span class="keywordflow">return</span> exp(points)
<a name="l00067"></a>00067 
<a name="l00068"></a>00068     @classmethod
<a name="l00069"></a><a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#a500dbfb8b931845cbc51e48743405068">00069</a>     <span class="keyword">def </span><a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#a500dbfb8b931845cbc51e48743405068">cinf_load</a>(cls, points, time=0):
<a name="l00070"></a>00070         <span class="stringliteral">&quot;&quot;&quot; rhs. &quot;&quot;&quot;</span>
<a name="l00071"></a>00071         <span class="keywordflow">return</span> (d + c + r) * exp(points)
<a name="l00072"></a>00072 
<a name="l00073"></a>00073     @classmethod
<a name="l00074"></a>00074     <span class="keyword">def </span>exact_solution(cls, points, time=0):  <span class="comment"># Test 2</span>
<a name="l00075"></a>00075         <span class="keywordflow">return</span> points * (3 + points)
<a name="l00076"></a>00076 
<a name="l00077"></a>00077     @classmethod
<a name="l00078"></a>00078     <span class="keyword">def </span>gradient(cls, points, time=0):
<a name="l00079"></a>00079         <span class="keywordflow">return</span> 2 * d * points + d * 3
<a name="l00080"></a>00080 
<a name="l00081"></a>00081     @classmethod
<a name="l00082"></a>00082     <span class="keyword">def </span>load(cls, points, time=0):
<a name="l00083"></a>00083         <span class="keywordflow">return</span> 2 * d * ones(points.shape) + c * (3 + 2 * points) + \
<a name="l00084"></a>00084                                         r * points * (3 + points)
<a name="l00085"></a>00085 
<a name="l00086"></a><a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#a9e8bb340c99056adb1da0cb6aa8758f3">00086</a>     <span class="keyword">def </span><a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#a9e8bb340c99056adb1da0cb6aa8758f3">setUp</a>(self):
<a name="l00087"></a>00087         <span class="stringliteral">&quot;&quot;&quot; I don&#39;t know how to avoid this &quot;&quot;&quot;</span>
<a name="l00088"></a>00088 
<a name="l00089"></a>00089         self.<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#aa8ef04bcbb8178d95e01c0043206cfc4">m_nsegs</a> = 100
<a name="l00090"></a>00090         self.<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#af54fd235231b4239ebcc2d17510cb0a2">m_xl</a> = -1
<a name="l00091"></a>00091         self.<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#a2eda04e3f5135a36cfc252087d4aa502">m_xr</a> = 1
<a name="l00092"></a>00092         self.<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#a528429e425b0e0b4075ae0cdc48985fd">m_quad</a> = <a class="code" href="classutils_1_1Quadrature_1_1LegendreGaussQuadrature.html">LegendreGaussQuadrature</a>(10)
<a name="l00093"></a>00093         self.<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#a1513a5db91c8e57aba968d48ab026184">m_lagrange_p2</a> = LagrangeP2()
<a name="l00094"></a>00094         self.<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#a0e858b1007668e57e74536ae4dc45a3c">m_lagrange_p1</a> = <a class="code" href="classutils_1_1FemBases_1_1LagrangeP1.html">LagrangeP1</a>()
<a name="l00095"></a>00095 
<a name="l00096"></a>00096         self.<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#af17271cbc6aa9bca11002250a32146b0">m_error_tol</a> = 1.0e-03
<a name="l00097"></a>00097 
<a name="l00098"></a>00098         self.<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#a0a5b7fb9116508daa9eab6341cb8a4ab">m_shape_funct</a> = self.<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#a0e858b1007668e57e74536ae4dc45a3c">m_lagrange_p1</a>
<a name="l00099"></a>00099         self.<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#a0a5b7fb9116508daa9eab6341cb8a4ab">m_shape_funct</a> = self.<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html#a1513a5db91c8e57aba968d48ab026184">m_lagrange_p2</a>
<a name="l00100"></a>00100 
<a name="l00101"></a>00101     @staticmethod
<a name="l00102"></a>00102     <span class="keyword">def </span>_comp_errors(mesh, sfuncts, numeric_sol, exact, time=0):
<a name="l00103"></a>00103         <span class="stringliteral">&quot;&quot;&quot; reconstruct to plot &quot;&quot;&quot;</span>
<a name="l00104"></a>00104 
<a name="l00105"></a>00105         recons = <a class="code" href="classutils_1_1FemToReal_1_1FemToReal.html">FemToReal</a>(mesh, sfuncts)
<a name="l00106"></a>00106         solu = recons.reconstruct(numeric_sol)
<a name="l00107"></a>00107         y1 = exact(solu[:, 0], time)
<a name="l00108"></a>00108 
<a name="l00109"></a>00109         <span class="keywordflow">return</span> linalg.norm(solu[:, 1].flatten() - y1.flatten())
<a name="l00110"></a>00110 
<a name="l00111"></a>00111 
<a name="l00112"></a><a class="code" href="classtestPdeSolvers_1_1Projection.html">00112</a> <span class="keyword">class </span><a class="code" href="classtestPdeSolvers_1_1Projection.html">Projection</a>(<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html">PdeTestSuite</a>):
<a name="l00113"></a>00113 
<a name="l00114"></a>00114     <span class="stringliteral">&quot;&quot;&quot; Test projection operator &quot;&quot;&quot;</span>
<a name="l00115"></a>00115 
<a name="l00116"></a>00116     <span class="keyword">def </span>runTest(self):
<a name="l00117"></a>00117         mesh = Grid1D(self.m_nsegs, self.m_xl, self.m_xr)
<a name="l00118"></a>00118 
<a name="l00119"></a>00119         sfuncts = self.m_shape_funct
<a name="l00120"></a>00120         numeric_sol = ProjOnShapeFunctions(sfuncts, self.m_quad, mesh,
<a name="l00121"></a>00121                               self.exact_solution)
<a name="l00122"></a>00122         error_norm = self._comp_errors(mesh, sfuncts, numeric_sol,
<a name="l00123"></a>00123                 self.exact_solution)
<a name="l00124"></a>00124         self.assert_(self.m_error_tol &gt; abs(error_norm))
<a name="l00125"></a>00125 
<a name="l00126"></a>00126 
<a name="l00127"></a><a class="code" href="classtestPdeSolvers_1_1AssembledMatrices.html">00127</a> <span class="keyword">class </span><a class="code" href="classtestPdeSolvers_1_1AssembledMatrices.html">AssembledMatrices</a>(<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html">PdeTestSuite</a>):
<a name="l00128"></a>00128 
<a name="l00129"></a>00129     <span class="stringliteral">&quot;&quot;&quot;   a*u_xx + b*u_x + c*u  = load</span>
<a name="l00130"></a>00130 <span class="stringliteral">          BC : Dirichlet</span>
<a name="l00131"></a>00131 <span class="stringliteral">    &quot;&quot;&quot;</span>
<a name="l00132"></a>00132 
<a name="l00133"></a><a class="code" href="classtestPdeSolvers_1_1AssembledMatrices.html#a9794e3d012369e8bc4e96856f224fc17">00133</a>     <span class="keyword">def </span><a class="code" href="classtestPdeSolvers_1_1AssembledMatrices.html#a9794e3d012369e8bc4e96856f224fc17">runTest</a>(self):
<a name="l00134"></a>00134         <span class="stringliteral">&quot;&quot;&quot; assemble global matrix, project exact solution, project</span>
<a name="l00135"></a>00135 <span class="stringliteral">            exact solution and compare agains projected rhs.</span>
<a name="l00136"></a>00136 <span class="stringliteral">        &quot;&quot;&quot;</span>
<a name="l00137"></a>00137         pde_solver = <a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html">SecondOrderStatic1D</a>(self.m_nsegs, self.m_xl, self.m_xr)
<a name="l00138"></a>00138 
<a name="l00139"></a>00139         sfuncts = self.m_shape_funct
<a name="l00140"></a>00140         pde_solver.set_sfunc_and_quads(sfuncts, self.m_quad)
<a name="l00141"></a>00141         (d_is_real, c_is_real, r_is_real) = (<span class="keyword">True</span>, <span class="keyword">True</span>, <span class="keyword">True</span>)
<a name="l00142"></a>00142         pde_solver.set_cos(d, c, r, d_is_real, c_is_real, r_is_real)
<a name="l00143"></a>00143         pde_solver.set_load(self.load)
<a name="l00144"></a>00144 
<a name="l00145"></a>00145         pde_solver.set_bd_conditions(self.exact_solution(self.m_xl),
<a name="l00146"></a>00146                                      self.exact_solution(self.m_xr))
<a name="l00147"></a>00147 
<a name="l00148"></a>00148         <span class="comment"># Get the matrices in diagonal form</span>
<a name="l00149"></a>00149         stiff_diag = pde_solver.get_stiff_dformat()
<a name="l00150"></a>00150         data = [list(stiff_diag[:, 0].flatten()), list(stiff_diag[:,
<a name="l00151"></a>00151                 1].flatten()), list(stiff_diag[:, 2].flatten())]
<a name="l00152"></a>00152         diags = [0, 1, -1]
<a name="l00153"></a>00153 
<a name="l00154"></a>00154         <span class="keywordflow">if</span> 3 == sfuncts.dof():
<a name="l00155"></a>00155             data.append(list(stiff_diag[:, 3].flatten()))
<a name="l00156"></a>00156             data.append(list(stiff_diag[:, 4].flatten()))
<a name="l00157"></a>00157             diags.append(2)
<a name="l00158"></a>00158             diags.append(-2)
<a name="l00159"></a>00159 
<a name="l00160"></a>00160         mat_size = stiff_diag[:, 0].size
<a name="l00161"></a>00161 
<a name="l00162"></a>00162         sys = spdiags(asarray(data), asarray(diags), mat_size, mat_size).tocsr()
<a name="l00163"></a>00163         rhs = pde_solver.get_load_terms()
<a name="l00164"></a>00164 
<a name="l00165"></a>00165         mesh = pde_solver.get_mesh()
<a name="l00166"></a>00166         exact_projected = ProjOnShapeFunctions(sfuncts, self.m_quad, mesh,
<a name="l00167"></a>00167                 self.exact_solution)
<a name="l00168"></a>00168         rhs[0] += self.gradient(self.m_xl)
<a name="l00169"></a>00169         rhs[-1] -= self.gradient(self.m_xr)
<a name="l00170"></a>00170 
<a name="l00171"></a>00171         error_norm = linalg.norm(sys * exact_projected - rhs)
<a name="l00172"></a>00172         self.assert_(self.m_error_tol &gt; abs(error_norm))
<a name="l00173"></a>00173 
<a name="l00174"></a>00174 
<a name="l00175"></a><a class="code" href="classtestPdeSolvers_1_1SolvePoisson1D.html">00175</a> <span class="keyword">class </span><a class="code" href="classtestPdeSolvers_1_1SolvePoisson1D.html">SolvePoisson1D</a>(<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html">PdeTestSuite</a>):
<a name="l00176"></a>00176 
<a name="l00177"></a>00177     <span class="stringliteral">&quot;&quot;&quot;   a*u_xx + b*u_x + c*u  = self.m_load</span>
<a name="l00178"></a>00178 <span class="stringliteral">          BC : Dirichlet</span>
<a name="l00179"></a>00179 <span class="stringliteral">    &quot;&quot;&quot;</span>
<a name="l00180"></a>00180 
<a name="l00181"></a><a class="code" href="classtestPdeSolvers_1_1SolvePoisson1D.html#a6a38e92c347224c3bdf9b293ee00afba">00181</a>     <span class="keyword">def </span><a class="code" href="classtestPdeSolvers_1_1SolvePoisson1D.html#a6a38e92c347224c3bdf9b293ee00afba">runTest</a>(self):
<a name="l00182"></a>00182         <span class="stringliteral">&quot;&quot;&quot; Make sure the static engine is working fine. &quot;&quot;&quot;</span>
<a name="l00183"></a>00183 
<a name="l00184"></a>00184         pde_solver = <a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html">SecondOrderStatic1D</a>(self.m_nsegs, self.m_xl, self.m_xr)
<a name="l00185"></a>00185 
<a name="l00186"></a>00186         sfuncts = self.m_shape_funct
<a name="l00187"></a>00187         pde_solver.set_sfunc_and_quads(sfuncts, self.m_quad)
<a name="l00188"></a>00188 
<a name="l00189"></a>00189         (d_is_real, c_is_real, r_is_real) = (<span class="keyword">True</span>, <span class="keyword">True</span>, <span class="keyword">True</span>)
<a name="l00190"></a>00190         pde_solver.set_cos(d, c, r, d_is_real, c_is_real, r_is_real)
<a name="l00191"></a>00191         pde_solver.set_load(self.load)
<a name="l00192"></a>00192 
<a name="l00193"></a>00193         pde_solver.set_bd_conditions(self.exact_solution(self.m_xl),
<a name="l00194"></a>00194                 self.exact_solution(self.m_xr))
<a name="l00195"></a>00195 
<a name="l00196"></a>00196         numeric_sol = pde_solver.solve()
<a name="l00197"></a>00197         mesh = pde_solver.get_mesh()
<a name="l00198"></a>00198         error_norm = self._comp_errors(mesh, sfuncts, numeric_sol,
<a name="l00199"></a>00199                 self.exact_solution, 0)
<a name="l00200"></a>00200         self.assert_(self.m_error_tol &gt; abs(error_norm))
<a name="l00201"></a>00201 
<a name="l00202"></a>00202 
<a name="l00203"></a><a class="code" href="classtestPdeSolvers_1_1RateOfConvergenceStatic.html">00203</a> <span class="keyword">class </span><a class="code" href="classtestPdeSolvers_1_1RateOfConvergenceStatic.html">RateOfConvergenceStatic</a>(<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html">PdeTestSuite</a>):
<a name="l00204"></a>00204     <span class="stringliteral">&quot;&quot;&quot; Convergence for lagrange P1 and lagrange P2 methods.&quot;&quot;&quot;</span>
<a name="l00205"></a>00205 
<a name="l00206"></a>00206     <span class="keyword">def </span>runTest(self):
<a name="l00207"></a>00207         <span class="keywordflow">print</span> <span class="stringliteral">&#39; &#39;</span>
<a name="l00208"></a>00208         conv_log = logging.getLogger(<span class="stringliteral">&#39;RateOfConvergence&#39;</span>)
<a name="l00209"></a>00209 
<a name="l00210"></a>00210         nsegs = asarray([int(2 ** k) <span class="keywordflow">for</span> k <span class="keywordflow">in</span> range(2, 12)], <span class="stringliteral">&#39;int&#39;</span>)
<a name="l00211"></a>00211         conv_log.info(<span class="stringliteral">&#39;             exp(x) &#39;</span>)
<a name="l00212"></a>00212         conv_log.info(<span class="stringliteral">&#39;    n          error      log2(ratio)&#39;</span>)
<a name="l00213"></a>00213         conv_log.info(<span class="stringliteral">&#39;Lagrange P1&#39;</span>)
<a name="l00214"></a>00214         (d_is_real, c_is_real, r_is_real) = (<span class="keyword">True</span>, <span class="keyword">True</span>, <span class="keyword">True</span>)
<a name="l00215"></a>00215         <span class="keywordflow">for</span> sfuncts <span class="keywordflow">in</span> [self.m_lagrange_p1, self.m_lagrange_p2]:
<a name="l00216"></a>00216             prev = .050
<a name="l00217"></a>00217             <span class="keywordflow">for</span> k <span class="keywordflow">in</span> nsegs:
<a name="l00218"></a>00218                 pde_solver = <a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html">SecondOrderStatic1D</a>(k, self.m_xl, self.m_xr)
<a name="l00219"></a>00219 
<a name="l00220"></a>00220                 pde_solver.set_sfunc_and_quads(sfuncts, self.m_quad)
<a name="l00221"></a>00221 
<a name="l00222"></a>00222                 pde_solver.set_cos(d, c, r, d_is_real, c_is_real, r_is_real)
<a name="l00223"></a>00223                 pde_solver.set_load(self.cinf_load)
<a name="l00224"></a>00224 
<a name="l00225"></a>00225                 pde_solver.set_bd_conditions(self.cinf_solution(self.m_xl),
<a name="l00226"></a>00226                         self.cinf_solution(self.m_xr))
<a name="l00227"></a>00227 
<a name="l00228"></a>00228                 numeric_sol = pde_solver.solve()
<a name="l00229"></a>00229                 mesh = pde_solver.get_mesh()
<a name="l00230"></a>00230                 l2_error = self._comp_errors(mesh, sfuncts, numeric_sol,
<a name="l00231"></a>00231                         self.cinf_solution, 0)
<a name="l00232"></a>00232                 conv_log.info(<span class="stringliteral">&#39; %5d    %12.11f    %12.11f&#39;</span> % (k,
<a name="l00233"></a>00233                                 l2_error, log2(prev / l2_error)))
<a name="l00234"></a>00234                 prev = l2_error
<a name="l00235"></a>00235             conv_log.info(<span class="stringliteral">&#39;&#39;</span>)
<a name="l00236"></a>00236             conv_log.info(<span class="stringliteral">&#39;Lagrange P2&#39;</span>)
<a name="l00237"></a>00237 
<a name="l00238"></a>00238 
<a name="l00239"></a><a class="code" href="classtestPdeSolvers_1_1Diffusion1D.html">00239</a> <span class="keyword">class </span><a class="code" href="classtestPdeSolvers_1_1Diffusion1D.html">Diffusion1D</a>(<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html">PdeTestSuite</a>):
<a name="l00240"></a>00240     <span class="stringliteral">&quot;&quot;&quot; The most important engine in the GBM pricing suite. &quot;&quot;&quot;</span>
<a name="l00241"></a>00241 
<a name="l00242"></a>00242     <span class="keyword">def </span>exact_sol(self, x, time=0):
<a name="l00243"></a>00243         <span class="keywordflow">return</span> exp(self.<a class="code" href="classtestPdeSolvers_1_1Diffusion1D.html#a7919ff5d230c2d9d7aaaa218d895b74b">m_d</a> * time) * exp(-x)
<a name="l00244"></a>00244 
<a name="l00245"></a>00245     <span class="keyword">def </span>runTest(self):
<a name="l00246"></a>00246         <span class="keywordflow">print</span> <span class="stringliteral">&#39; &#39;</span>
<a name="l00247"></a>00247         ntime_steps = 40
<a name="l00248"></a>00248         time2simulate = 2.0
<a name="l00249"></a>00249 
<a name="l00250"></a>00250         self.<a class="code" href="classtestPdeSolvers_1_1Diffusion1D.html#a7919ff5d230c2d9d7aaaa218d895b74b">m_d</a> = 1
<a name="l00251"></a>00251         self.<a class="code" href="classtestPdeSolvers_1_1Diffusion1D.html#adda4a85f74a1e42ce9e410769a824747">m_nsegs</a> = 2
<a name="l00252"></a>00252         pde_solver = <a class="code" href="classmodels_1_1CDRSolver_1_1CDRSolver.html">CDRSolver</a>(self.<a class="code" href="classtestPdeSolvers_1_1Diffusion1D.html#adda4a85f74a1e42ce9e410769a824747">m_nsegs</a>, self.m_xl, self.m_xr)
<a name="l00253"></a>00253 
<a name="l00254"></a>00254         pde_solver.set_sfunc_and_quads(self.m_shape_funct, self.m_quad)
<a name="l00255"></a>00255 
<a name="l00256"></a>00256         (d_is_real, c_is_real, r_is_real) = (<span class="keyword">True</span>, <span class="keyword">True</span>, <span class="keyword">True</span>)
<a name="l00257"></a>00257         pde_solver.set_diffus_cos(self.<a class="code" href="classtestPdeSolvers_1_1Diffusion1D.html#a7919ff5d230c2d9d7aaaa218d895b74b">m_d</a>, 0.0, 0.0, d_is_real, c_is_real,
<a name="l00258"></a>00258                                   r_is_real)
<a name="l00259"></a>00259 
<a name="l00260"></a>00260       <span class="comment"># pde_solver.set_load(f)</span>
<a name="l00261"></a>00261 
<a name="l00262"></a>00262         pde_solver.set_ivalf(self.<a class="code" href="classtestPdeSolvers_1_1Diffusion1D.html#af8f7e183c122e96d7e2c3ff4fabf369a">exact_sol</a>)
<a name="l00263"></a>00263         pde_solver.set_lbc(self.<a class="code" href="classtestPdeSolvers_1_1Diffusion1D.html#af8f7e183c122e96d7e2c3ff4fabf369a">exact_sol</a>)
<a name="l00264"></a>00264         pde_solver.set_rbc(self.<a class="code" href="classtestPdeSolvers_1_1Diffusion1D.html#af8f7e183c122e96d7e2c3ff4fabf369a">exact_sol</a>)
<a name="l00265"></a>00265 
<a name="l00266"></a>00266         time_stepper = <a class="code" href="classsolvers_1_1DirichletTimeStepper_1_1DirichletTimeStepper.html">DirichletTimeStepper</a>()
<a name="l00267"></a>00267 
<a name="l00268"></a>00268         <span class="comment"># Use 5000 time steps to get accurancy</span>
<a name="l00269"></a>00269         time_stepper.set_time_step_method(<span class="stringliteral">&#39;ei&#39;</span>)
<a name="l00270"></a>00270         <span class="comment">#time_stepper.set_time_step_method(&#39;cn&#39;)</span>
<a name="l00271"></a>00271 
<a name="l00272"></a>00272         time_stepper.set_dolog(<span class="keyword">True</span>)
<a name="l00273"></a>00273         time_stepper.set_number_steps(ntime_steps)
<a name="l00274"></a>00274         time_stepper.set_time2simulate(time2simulate)
<a name="l00275"></a>00275 
<a name="l00276"></a>00276         pde_solver.set_time_stepper(time_stepper)
<a name="l00277"></a>00277 
<a name="l00278"></a>00278         numeric_sol = pde_solver.solve()
<a name="l00279"></a>00279         mesh = pde_solver.get_mesh()
<a name="l00280"></a>00280 
<a name="l00281"></a>00281         error_norm = self._comp_errors(mesh, self.m_shape_funct, numeric_sol,
<a name="l00282"></a>00282                 self.<a class="code" href="classtestPdeSolvers_1_1Diffusion1D.html#af8f7e183c122e96d7e2c3ff4fabf369a">exact_sol</a>, time2simulate)
<a name="l00283"></a>00283         <span class="keywordflow">print</span> error_norm
<a name="l00284"></a>00284         self.assert_(1.0e-02 &gt; abs(error_norm))
<a name="l00285"></a>00285 
<a name="l00286"></a>00286 
<a name="l00287"></a><a class="code" href="classtestPdeSolvers_1_1Poisson2D.html">00287</a> <span class="keyword">class </span><a class="code" href="classtestPdeSolvers_1_1Poisson2D.html">Poisson2D</a>(<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html">PdeTestSuite</a>):
<a name="l00288"></a>00288     <span class="stringliteral">&quot;&quot;&quot; Test static solver. &quot;&quot;&quot;</span>
<a name="l00289"></a>00289 
<a name="l00290"></a>00290     <span class="comment"># 3 test cases, 2 Exact solutions and 1 very smooth</span>
<a name="l00291"></a>00291 
<a name="l00292"></a><a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#af209b5ddc74e6e1ca5a16af0db99e92e">00292</a>     <span class="keyword">def </span><a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#af209b5ddc74e6e1ca5a16af0db99e92e">exact_solution_2d</a>(self, points):
<a name="l00293"></a>00293         <span class="stringliteral">&quot;&quot;&quot; known solutions. &quot;&quot;&quot;</span>
<a name="l00294"></a>00294 
<a name="l00295"></a>00295         x = points[:, 0].reshape((points[:, 0].size, 1))
<a name="l00296"></a>00296         y = points[:, 1].reshape((points[:, 0].size, 1))
<a name="l00297"></a>00297 
<a name="l00298"></a>00298         <span class="keywordflow">return</span> cos(x)-sin(y)
<a name="l00299"></a>00299         <span class="comment">#return 0.2 + 0.1 * exp( -0.3 * x)</span>
<a name="l00300"></a>00300         <span class="comment">#return x** 3</span>
<a name="l00301"></a>00301         <span class="comment">#return ones(x)</span>
<a name="l00302"></a>00302 
<a name="l00303"></a><a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#a291b2bdb3830d4956b7040b5d77cdb50">00303</a>     <span class="keyword">def </span><a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#a291b2bdb3830d4956b7040b5d77cdb50">load_2d</a>(self, points):
<a name="l00304"></a>00304         <span class="stringliteral">&quot;&quot;&quot; Force term in mechanical engineer. &quot;&quot;&quot;</span>
<a name="l00305"></a>00305 
<a name="l00306"></a>00306         x, y = points[0], points[1]
<a name="l00307"></a>00307 
<a name="l00308"></a>00308         <span class="keywordflow">return</span> cos(x) - sin(y)
<a name="l00309"></a>00309         <span class="comment">#return -0.09 * exp( -0.3 * x)</span>
<a name="l00310"></a>00310         <span class="comment">#return -6 * x</span>
<a name="l00311"></a>00311         <span class="comment">#return 0</span>
<a name="l00312"></a>00312 
<a name="l00313"></a>00313     <span class="keyword">def </span>_init_solver(self):
<a name="l00314"></a>00314         <span class="stringliteral">&quot;&quot;&quot; gloabal parametes for all test cases. &quot;&quot;&quot;</span>
<a name="l00315"></a>00315 
<a name="l00316"></a>00316         delta_x, delta_y = 10. , 0.05
<a name="l00317"></a>00317         delta_x, delta_y = .025 , 0.025
<a name="l00318"></a>00318         self.<a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#a73f6e7f1313c6d66370cef7650a9aa8c">m_p2d</a> = <a class="code" href="classmodels_1_1Poisson2DFiniteDifference_1_1Poisson2DFiniteDifference.html">Poisson2DFiniteDifference</a>()
<a name="l00319"></a>00319 
<a name="l00320"></a>00320         self.m_p2d.set_simu_domain(-1.5, -1., 1., 1.)
<a name="l00321"></a>00321         <span class="comment">#self.m_p2d.set_simu_domain(40, 0, 120, 2)</span>
<a name="l00322"></a>00322         self.m_p2d.set_xlxr(self.<a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#af209b5ddc74e6e1ca5a16af0db99e92e">exact_solution_2d</a>,
<a name="l00323"></a>00323                                   self.<a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#af209b5ddc74e6e1ca5a16af0db99e92e">exact_solution_2d</a>)
<a name="l00324"></a>00324         self.m_p2d.set_bott_top(self.<a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#af209b5ddc74e6e1ca5a16af0db99e92e">exact_solution_2d</a>, self.<a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#af209b5ddc74e6e1ca5a16af0db99e92e">exact_solution_2d</a>)
<a name="l00325"></a>00325         self.m_p2d.set_dx_dy(delta_x, delta_y)
<a name="l00326"></a>00326 
<a name="l00327"></a><a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#afa8925a1c570435784f71ecfe7a4754c">00327</a>     <span class="keyword">def </span><a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#afa8925a1c570435784f71ecfe7a4754c">test_analytical_load</a>(self):
<a name="l00328"></a>00328         <span class="stringliteral">&quot;&quot;&quot; Let the solver know about the load as an analytical expression. &quot;&quot;&quot;</span>
<a name="l00329"></a>00329 
<a name="l00330"></a>00330         self.m_p2d.set_continuos_load(self.<a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#a291b2bdb3830d4956b7040b5d77cdb50">load_2d</a>)
<a name="l00331"></a>00331         <span class="keywordflow">return</span> self.m_p2d.solve()
<a name="l00332"></a>00332 
<a name="l00333"></a><a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#a1c08edf61882a5a067aaf3e30aff832e">00333</a>     <span class="keyword">def </span><a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#a1c08edf61882a5a067aaf3e30aff832e">test_discrete_load</a>(self):
<a name="l00334"></a>00334         <span class="stringliteral">&quot;&quot;&quot; Let the solver know about the load at the mesh points. &quot;&quot;&quot;</span>
<a name="l00335"></a>00335 
<a name="l00336"></a>00336         <span class="keyword">from</span> itertools <span class="keyword">import</span> izip, count
<a name="l00337"></a>00337 
<a name="l00338"></a>00338         (x_mesh, y_mesh) = self.m_p2d.get_mesh()
<a name="l00339"></a>00339 
<a name="l00340"></a>00340         <span class="comment"># Analytical Load</span>
<a name="l00341"></a>00341 
<a name="l00342"></a>00342         (x_coor, Y) = meshgrid(x_mesh, y_mesh)
<a name="l00343"></a>00343         discrete_load = empty((x_coor.size, 1))
<a name="l00344"></a>00344         <span class="keywordflow">for</span> (i, val) <span class="keywordflow">in</span> izip(count(), c_[x_coor.flatten(), Y.flatten()]):
<a name="l00345"></a>00345             discrete_load[i] = self.<a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#a291b2bdb3830d4956b7040b5d77cdb50">load_2d</a>(val)
<a name="l00346"></a>00346         discrete_load = discrete_load.reshape((y_mesh.size, x_mesh.size)).T
<a name="l00347"></a>00347 
<a name="l00348"></a>00348         self.m_p2d.set_discrete_load(discrete_load)
<a name="l00349"></a>00349         <span class="keywordflow">return</span> self.m_p2d.solve()
<a name="l00350"></a>00350 
<a name="l00351"></a><a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#a24d13b485743693ebf90f9da947d5e46">00351</a>     <span class="keyword">def </span><a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#a24d13b485743693ebf90f9da947d5e46">runTest</a>(self):
<a name="l00352"></a>00352         <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00353"></a>00353 <span class="stringliteral">            Solve a simple laplace problem using continuos load and</span>
<a name="l00354"></a>00354 <span class="stringliteral">            discretize load.</span>
<a name="l00355"></a>00355 <span class="stringliteral">        &quot;&quot;&quot;</span>
<a name="l00356"></a>00356         <span class="comment"># Analytical Load</span>
<a name="l00357"></a>00357 
<a name="l00358"></a>00358         self.<a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#a0f97ff7a0535301618861fff529700b7">_init_solver</a>()
<a name="l00359"></a>00359         (x_mesh, y_mesh, solu) = self.<a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#afa8925a1c570435784f71ecfe7a4754c">test_analytical_load</a>()
<a name="l00360"></a>00360 
<a name="l00361"></a>00361         <span class="comment"># Exact solution</span>
<a name="l00362"></a>00362 
<a name="l00363"></a>00363         (x_coor, Y) = meshgrid(x_mesh, y_mesh[::-1])
<a name="l00364"></a>00364         analytical = self.<a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#af209b5ddc74e6e1ca5a16af0db99e92e">exact_solution_2d</a>(c_[x_coor.flatten(), Y.flatten()])
<a name="l00365"></a>00365 
<a name="l00366"></a>00366         plot_results = <span class="keyword">False</span>
<a name="l00367"></a>00367         <span class="keywordflow">if</span> plot_results:
<a name="l00368"></a>00368             dplots = <a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html">DerivativePlots</a>()
<a name="l00369"></a>00369             dplots.set_vol_surface(x_coor, Y, solu,
<a name="l00370"></a>00370                                  solu-analytical.reshape(solu.shape))
<a name="l00371"></a>00371 
<a name="l00372"></a>00372             dplots.plot_vol_surfaces()
<a name="l00373"></a>00373 
<a name="l00374"></a>00374         <span class="comment"># a) Numeric vs Exact.</span>
<a name="l00375"></a>00375 
<a name="l00376"></a>00376         l2_error = linalg.norm(analytical.flatten() - solu.flatten())
<a name="l00377"></a>00377         self.assert_(self.m_error_tol &gt; l2_error)
<a name="l00378"></a>00378 
<a name="l00379"></a>00379         <span class="comment"># Discrete Load</span>
<a name="l00380"></a>00380 
<a name="l00381"></a>00381         self.<a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#a0f97ff7a0535301618861fff529700b7">_init_solver</a>()
<a name="l00382"></a>00382         (x_mesh, y_mesh, solu) = self.<a class="code" href="classtestPdeSolvers_1_1Poisson2D.html#a1c08edf61882a5a067aaf3e30aff832e">test_discrete_load</a>()
<a name="l00383"></a>00383 
<a name="l00384"></a>00384         <span class="comment"># b) Numeric vs Exact.</span>
<a name="l00385"></a>00385 
<a name="l00386"></a>00386         l2_error = linalg.norm(analytical.flatten() - solu.flatten())
<a name="l00387"></a>00387         self.assert_(self.m_error_tol &gt; l2_error)
<a name="l00388"></a>00388 
<a name="l00389"></a><a class="code" href="classtestPdeSolvers_1_1Splines.html">00389</a> <span class="keyword">class </span><a class="code" href="classtestPdeSolvers_1_1Splines.html">Splines</a>(<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html">PdeTestSuite</a>):
<a name="l00390"></a>00390     <span class="stringliteral">&quot;&quot;&quot; Variable coeffienents pde solver. &quot;&quot;&quot;</span>
<a name="l00391"></a>00391 
<a name="l00392"></a>00392     <span class="keyword">def </span>runTest(self):
<a name="l00393"></a>00393         x = asarray(linspace(0, self.m_nsegs, self.m_nsegs, <span class="keyword">False</span>))
<a name="l00394"></a>00394         f = self.gradient
<a name="l00395"></a>00395         y = f(x)
<a name="l00396"></a>00396 
<a name="l00397"></a>00397         my_spline = <a class="code" href="classutils_1_1Spline_1_1Spline.html">Spline</a>()
<a name="l00398"></a>00398         my_spline.spline(x, y)
<a name="l00399"></a>00399 
<a name="l00400"></a>00400         <span class="comment"># chk Results</span>
<a name="l00401"></a>00401 
<a name="l00402"></a>00402         shift = 0.5
<a name="l00403"></a>00403         yt = f(x + shift * ones(x.shape))
<a name="l00404"></a>00404         sp_vals = asarray([my_spline.value([x[s] + shift], s) <span class="keywordflow">for</span> s <span class="keywordflow">in</span>
<a name="l00405"></a>00405                        range(x.size - 1)]).flatten()
<a name="l00406"></a>00406         error_norm = linalg.norm(yt[:-1] - sp_vals)
<a name="l00407"></a>00407         <span class="keyword">assert</span> self.m_error_tol &gt; error_norm
<a name="l00408"></a>00408 
<a name="l00409"></a>00409 
<a name="l00410"></a><a class="code" href="classtestPdeSolvers_1_1ExactVsConstant.html">00410</a> <span class="keyword">class </span><a class="code" href="classtestPdeSolvers_1_1ExactVsConstant.html">ExactVsConstant</a>(<a class="code" href="classtestPdeSolvers_1_1PdeTestSuite.html">PdeTestSuite</a>):
<a name="l00411"></a>00411     <span class="stringliteral">&quot;&quot;&quot; compare the 2 solvers when the coeffients are constant. &quot;&quot;&quot;</span>
<a name="l00412"></a>00412 
<a name="l00413"></a><a class="code" href="classtestPdeSolvers_1_1ExactVsConstant.html#af7362f0a76c33ded2885338357bdc605">00413</a>     <span class="keyword">def </span><a class="code" href="classtestPdeSolvers_1_1ExactVsConstant.html#af7362f0a76c33ded2885338357bdc605">runTest</a>(self):
<a name="l00414"></a>00414         <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00415"></a>00415 <span class="stringliteral">            Compare the pde solver using constant coeffients and spline</span>
<a name="l00416"></a>00416 <span class="stringliteral">            variable coeffients.</span>
<a name="l00417"></a>00417 <span class="stringliteral">        &quot;&quot;&quot;</span>
<a name="l00418"></a>00418 
<a name="l00419"></a>00419 
<a name="l00420"></a>00420         sfuncts = self.m_shape_funct
<a name="l00421"></a>00421         mesh = Grid1D(self.m_nsegs, self.m_xl, self.m_xr)
<a name="l00422"></a>00422 
<a name="l00423"></a>00423         <span class="comment"># constant term PDE</span>
<a name="l00424"></a>00424 
<a name="l00425"></a>00425         is_real = <span class="keyword">True</span>
<a name="l00426"></a>00426         ass_const = <a class="code" href="classmodels_1_1AssembleStiffnesMassMatrices_1_1AssembleStiffnesMassMatrices.html">AssembleStiffnesMassMatrices</a>(mesh)
<a name="l00427"></a>00427         ass_const.set_sfunc_and_quads(sfuncts, self.m_quad)
<a name="l00428"></a>00428         ass_const.set_cos(d, c, r, is_real, is_real, is_real)
<a name="l00429"></a>00429         ass_const.discretize()
<a name="l00430"></a>00430         stiff_const = ass_const.get_stiffness()
<a name="l00431"></a>00431 
<a name="l00432"></a>00432         <span class="comment"># non-constant term PDE</span>
<a name="l00433"></a>00433 
<a name="l00434"></a>00434         ass_const = <a class="code" href="classmodels_1_1AssembleStiffnesMassMatrices_1_1AssembleStiffnesMassMatrices.html">AssembleStiffnesMassMatrices</a>(mesh)
<a name="l00435"></a>00435         x = mesh.get_grid()
<a name="l00436"></a>00436         dspline = <a class="code" href="classutils_1_1Spline_1_1Spline.html">Spline</a>(x, d * ones(x.shape))
<a name="l00437"></a>00437         cspline = <a class="code" href="classutils_1_1Spline_1_1Spline.html">Spline</a>(x, c * ones(x.shape))
<a name="l00438"></a>00438         rspline = <a class="code" href="classutils_1_1Spline_1_1Spline.html">Spline</a>(x, r * ones(x.shape))
<a name="l00439"></a>00439 
<a name="l00440"></a>00440         is_real = <span class="keyword">False</span>
<a name="l00441"></a>00441         ass_spline = <a class="code" href="classmodels_1_1AssembleStiffnesMassMatrices_1_1AssembleStiffnesMassMatrices.html">AssembleStiffnesMassMatrices</a>(mesh)
<a name="l00442"></a>00442         ass_spline.set_sfunc_and_quads(sfuncts, self.m_quad)
<a name="l00443"></a>00443         ass_spline.set_cos(dspline, cspline, rspline, \
<a name="l00444"></a>00444                 is_real, is_real, is_real)
<a name="l00445"></a>00445         ass_spline.discretize()
<a name="l00446"></a>00446         stiff_spline = ass_spline.get_stiffness()
<a name="l00447"></a>00447 
<a name="l00448"></a>00448         <span class="keyword">assert</span> stiff_const.shape == stiff_spline.shape
<a name="l00449"></a>00449         <span class="keyword">assert</span> self.m_error_tol &gt; linalg.norm(stiff_const - stiff_spline)
<a name="l00450"></a>00450 
<a name="l00451"></a>00451 
<a name="l00452"></a>00452 
<a name="l00453"></a>00453 <span class="keyword">def </span>my_suite():
<a name="l00454"></a>00454     <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00455"></a>00455 <span class="stringliteral">        Any running test should be added here.</span>
<a name="l00456"></a>00456 <span class="stringliteral">    &quot;&quot;&quot;</span>
<a name="l00457"></a>00457     suite = unittest.TestSuite()
<a name="l00458"></a>00458 
<a name="l00459"></a>00459     suite.addTest(<a class="code" href="classtestPdeSolvers_1_1Poisson2D.html">Poisson2D</a>())
<a name="l00460"></a>00460     suite.addTest(<a class="code" href="classtestPdeSolvers_1_1Projection.html">Projection</a>())
<a name="l00461"></a>00461     suite.addTest(<a class="code" href="classtestPdeSolvers_1_1AssembledMatrices.html">AssembledMatrices</a>())
<a name="l00462"></a>00462     suite.addTest(<a class="code" href="classtestPdeSolvers_1_1SolvePoisson1D.html">SolvePoisson1D</a>())
<a name="l00463"></a>00463     suite.addTest(<a class="code" href="classtestPdeSolvers_1_1Diffusion1D.html">Diffusion1D</a>())
<a name="l00464"></a>00464     suite.addTest(<a class="code" href="classtestPdeSolvers_1_1RateOfConvergenceStatic.html">RateOfConvergenceStatic</a>())
<a name="l00465"></a>00465 
<a name="l00466"></a>00466     suite.addTest(<a class="code" href="classtestPdeSolvers_1_1Splines.html">Splines</a>())
<a name="l00467"></a>00467     suite.addTest(<a class="code" href="classtestPdeSolvers_1_1ExactVsConstant.html">ExactVsConstant</a>())
<a name="l00468"></a>00468 
<a name="l00469"></a>00469     <span class="keywordflow">return</span> suite
<a name="l00470"></a>00470 
<a name="l00471"></a>00471 
<a name="l00472"></a>00472 <span class="keywordflow">if</span> __name__ == <span class="stringliteral">&#39;__main__&#39;</span>:
<a name="l00473"></a>00473 
<a name="l00474"></a>00474     runGlobalLogger()
<a name="l00475"></a>00475     runner = unittest.TextTestRunner(verbosity=2)
<a name="l00476"></a>00476     result = runner.run(my_suite())
<a name="l00477"></a>00477 
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Thu Dec 22 2011 05:17:53 for OptionsPricing by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
